package com.junjiao.util.dao.paging;

/**
 *说明：
 * 
 *排序条件
 * 
 *@创建：作者:Qi 创建时间：Sep 8, 2009
 *@修改历史：[序号](Qi Sep 8, 2009)<修改说明>
 */
public class QueryOrderby {

	private String propertyName;// 属性名

	private String ascOrDesc;// 升序/降序

	private boolean isOrderByPinyin;// 是否拼音排序

	public boolean isOrderByPinyin() {
		return isOrderByPinyin;
	}

	public void setOrderByPinyin(boolean isOrderByPinyin) {
		this.isOrderByPinyin = isOrderByPinyin;
	}

	public QueryOrderby() {
	}

	/**
	 * @param propertyName
	 *            : 属性名
	 * @param ascOrDesc
	 *            : 升序/降序
	 */
	public QueryOrderby(String propertyName, String ascOrDesc) {
		check(ascOrDesc);
		this.propertyName = propertyName;
		this.ascOrDesc = ascOrDesc;
	}

	private void check(String ascOrDesc) {
		if (!ascOrDesc.toUpperCase().equals("ASC")
				&& !ascOrDesc.toUpperCase().equals("DESC")) {
			throw new RuntimeException("ascOrDesc 必须是 asc或者desc");
		}
	}

	/** 获取orderby的组合的字符串 **/
	public StringBuffer getQueryOrderbyStr(String otherName) {
		StringBuffer sb = new StringBuffer();
		if (ascOrDesc == null || ascOrDesc.toString().equals(""))
			return sb;
		if (!propertyName.contains(" ")) {
			sb.append(otherName).append(".");
		}
		return sb.append(propertyName).append(" ").append(ascOrDesc);
	}

	/** 获取orderby的组合的字符串 added by jicheng **/
	public StringBuffer getPinyinQueryOrderbyStr(String otherName) {
		StringBuffer sb = new StringBuffer();
		if (ascOrDesc == null || ascOrDesc.toString().equals(""))
			return sb;
		return sb.append("nlssort(").append(otherName).append(".").append(
				propertyName).append(",").append(
				"'NLS_SORT=SCHINESE_PINYIN_M')").append(" ").append(ascOrDesc);
	}

	/** 获取属性名 **/
	public String getPropertyName() {
		return propertyName;
	}

	/** 设置属性名 **/
	public void setPropertyName(String propertyName) {
		this.propertyName = propertyName;
	}

	/** 获取升序/降序 **/
	public String getAscOrDesc() {
		return ascOrDesc;
	}

	/** 设置升序/降序 **/
	public void setAscOrDesc(String ascOrDesc) {
		check(ascOrDesc);
		this.ascOrDesc = ascOrDesc;
	}
}
